package com.pucheng.bracelet.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.Observer
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.base.BaseTitleActivity
import com.pucheng.bracelet.app.ext.KEY_FEEDBACK
import com.pucheng.bracelet.data.bean.FeedbackBean
import com.pucheng.bracelet.databinding.ActivityAboutBinding
import com.pucheng.bracelet.viewmodel.FeedBackViewModel
import kotlinx.android.synthetic.main.activity_feedback.*
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.demo.app.ext.showError

/**
 * 我要反馈
 */
class FeedBackActivity : BaseTitleActivity<FeedBackViewModel, ActivityAboutBinding>() {
    private lateinit var mAdapter: BaseQuickAdapter<FeedbackBean, BaseViewHolder>
    override fun layoutId(): Int = R.layout.activity_feedback
    override fun initView(savedInstanceState: Bundle?) {
        val mData = mutableListOf<FeedbackBean>()
//        mData.add(FeedbackBean("如何设置手环/手表时间？"))
//        mData.add(FeedbackBean("如何查看手环/手表消息通知内容？"))
//        mData.add(FeedbackBean("如何使用拍照功能？"))
//        mData.add(FeedbackBean("如何查看手表/手环电量？"))
//        mData.add(FeedbackBean("如何使用音乐控制功能？"))
//        mData.add(FeedbackBean("手表/手环充电多久满电？"))
//        mData.add(FeedbackBean("如何将手表/手环关机？"))
//        mData.add(FeedbackBean("手表/手环如何连接/如何同步数据？"))
//        mData.add(FeedbackBean("为什么手表/手环接收不到消息推送？"))
//        mData.add(FeedbackBean("手环如何解除绑定？"))
        mAdapter = object :
            BaseQuickAdapter<FeedbackBean, BaseViewHolder>(R.layout.item_feedback, mData) {
            override fun convert(holder: BaseViewHolder, item: FeedbackBean) {
                holder.setText(R.id.rv_feedback_name, item.title)
            }

        }
        rv_feedback.adapter = mAdapter
        mAdapter.setOnItemClickListener { _, _, position ->
            run {
                val mIntent = Intent(this@FeedBackActivity, FeedbackDetailsActivity::class.java)
                mIntent.putExtra(KEY_FEEDBACK, mData[position])
                startActivity(mIntent)
            }
        }
//
//        btn_feedback.click {
//            startActivity(
//                Intent(
//                    this,
//                    AddFeedbackActivity::class.java
//                )
//            )
//        }
//        btn_history_feedback.click {
//            startActivity(
//                Intent(
//                    this,
//                    FeedBackHistoryActivity::class.java
//                )
//            )
//        }
        mViewModel.getHelpData()
    }

    override fun titleText(): String = getString(R.string.feedback)

    override fun createObserver() {
        super.createObserver()
        mViewModel.helpData.observe(this, Observer {

            if (it.isSuccess) {
//                loadsir.showSuccess()
                mAdapter.setList(it.listData)
            } else {
//                loadsir.showError(it.errMessage)
            }
        })
    }
}